#include <ConnectionBroker/PacketUtils.h>
#include <ConnectionBroker/clientconnection/TcpClientConnection.h>
#include <ConnectionBroker/server/TcpServer.h>
#include <boost/bind.hpp>
#include <json/json.h>

using namespace ConnectionBroker;

TcpClientConnection::TcpClientConnection(boost::asio::io_service& pIoService, 
                                         TcpServer* pServer,
                                         boost::shared_ptr<boost::asio::ssl::context> pContext)
: 
ClientConnection(), 
TcpConnection(false, pIoService, pContext), 
mServer(pServer)
{
}

TcpClientConnection::~TcpClientConnection()
{
}

void TcpClientConnection::connectionEstablished()
{
   mServer->addClient(sharedFromThis());
   TcpConnection::connectionEstablished();
}

void TcpClientConnection::messageReceived(const Packet& pMessage)
{
   mServer->messageReceived(sharedFromThis(), pMessage);
}

void TcpClientConnection::onStop()
{
   TcpConnection::onStop();

   mServer->removeClient(sharedFromThis());
}

void TcpClientConnection::write(const Packet& pPacket)
{
   TcpConnection::send(pPacket);
}

